<?php

namespace app\api\controller\v1;

use app\common\controller\Api;
use app\common\logic\AddressLogic;
use app\common\model\Area;
use think\Db;
use think\Request;


/**
 * Token接口
 */
class Address extends Api
{
    protected $noNeedLogin = ['getCity', 'createJson', 'getCodeArea'];
    protected $noNeedRight = '*';
    protected $addressLogic = null;
    protected $beforeActionList = [
        'areaChange'  =>  ['only'=>'add'],
    ];

    public function __construct(Request $request = null)
    {
        $this->addressLogic = new AddressLogic();
        parent::__construct($request);
    }

    protected function areaChange() {
        $this->addressLogic->areaChange();

    }

    /**编辑修改*/
    public function add() {

        $this->addressLogic->add();
        $this->success('保存成功');
    }

    /**删除地址*/
    public function del() {
        $id = input('id/d', 0);
        $this->addressLogic->del($id);

        $this->success('删除成功');
    }


    public function listAddress() {
        $list = $this->addressLogic->addressList();

        $this->success('地址列表', $list);
    }

    public function getDefaultAddress() {
        $info = $this->addressLogic->getDefault();

        $this->success('默认地址', $info);
    }



    //设置订单收获地址
    public function setAddress() {
        $this->addressLogic->setAddress();
        $this->success('选择成功');
    }

}
